Preamble

library("forecast")
Warning: package 'forecast' was built under R version 3.1.3
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: timeDate
Loading required package: methods
This is forecast 5.9 

Hedge Fund Index

CISDM Equal Weighted Hedge Fund Index NAV, Monthly, 1990 - Present

# Remove earlier time points
data <- read.csv("http://ptrckprry.com/course/forecasting/data/hedge.csv")
data$date <- as.Date(data$date)
data <- subset(data, date >= "1990-01-01")

# Extract returns
hedge <- data$return
n <- length(hedge)
time <- 1:n
plot(time, hedge, type="l", col=2)

plot of chunk unnamed-chunk-2

ACF, PACF

Original Series

par(mfrow=c(1,2))
Acf(hedge)
Pacf(hedge)

plot of chunk unnamed-chunk-3

First Difference

par(mfrow=c(1,2))
Acf(diff(hedge))
Pacf(diff(hedge))

plot of chunk unnamed-chunk-4

AICC

d <- 0
for (p in 0:2) {
    for (q in 0:2) {
        fit <- Arima(hedge, c(p, d, q), include.constant=TRUE)
        cat("ARIMA(", p, ",", d, ",", q, ") : ", fit$aicc, "\n", sep="")
    }
}
ARIMA(0,0,0) : 1269
ARIMA(0,0,1) : 1249
ARIMA(0,0,2) : 1246
ARIMA(1,0,0) : 1244
ARIMA(1,0,1) : 1245
ARIMA(1,0,2) : 1247
ARIMA(2,0,0) : 1245
ARIMA(2,0,1) : 1247
ARIMA(2,0,2) : 1249

Estimation

(fit <- Arima(hedge, c(1, 0, 0), include.constant=TRUE))
Series: hedge 
ARIMA(1,0,0) with non-zero mean 

Coefficients:
        ar1  intercept
      0.292      0.943
s.e.  0.056      0.161

sigma^2 estimated as 3.84:  log likelihood=-619.2
AIC=1244   AICc=1244   BIC=1255

Diagnostic Checking

resid <- residuals(fit)
par(mfrow=c(1,2))
Acf(resid)
Pacf(resid)

plot of chunk unnamed-chunk-7

Ljung-Box Tests

Box.test(resid, lag=12, type="Ljung-Box", fitdf=2)

    Box-Ljung test

data:  resid
X-squared = 6.206, df = 10, p-value = 0.7977
Box.test(resid, lag=24, type="Ljung-Box", fitdf=2)

    Box-Ljung test

data:  resid
X-squared = 13.63, df = 22, p-value = 0.914
Box.test(resid, lag=36, type="Ljung-Box", fitdf=2)

    Box-Ljung test

data:  resid
X-squared = 22.21, df = 34, p-value = 0.9401
Box.test(resid, lag=48, type="Ljung-Box", fitdf=2)

    Box-Ljung test

data:  resid
X-squared = 34.22, df = 46, p-value = 0.9

Histogram of Residuals

hist(resid)

plot of chunk unnamed-chunk-9

Normal Probability Plot of Residuals

qqnorm(resid)

plot of chunk unnamed-chunk-10

Simulating from The Fitted Model

nsim <- 5
for (i in 1:nsim) {
    plot(time, hedge, col=2, t="l")
    lines(time, simulate(fit), col=1)
}

plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11

Bootstrap Simulations

nsim <- 5
for (i in 1:nsim) {
    plot(time, hedge, col=2, t="l")
    lines(time, simulate(fit, bootstrap=TRUE), col=1)
}

plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12

Gaussian Forecasts

plot(forecast(fit, level=c(95, 99)))

plot of chunk unnamed-chunk-13

Bootstrap Forecasts

plot(forecast(fit, level=c(95, 99), bootstrap=TRUE, npaths=10000))

plot of chunk unnamed-chunk-14

Comparison

forecast(fit, h=2, level=c(80, 95, 99, 99.9))
    Point Forecast  Lo 80 Hi 80  Lo 95 Hi 95  Lo 99 Hi 99 Lo 99.9 Hi 99.9
297         0.9654 -1.546 3.476 -2.875 4.806 -4.082 6.013  -5.482   7.413
298         0.9494 -1.666 3.565 -3.051 4.950 -4.308 6.207  -5.767   7.666
forecast(fit, h=2, level=c(80, 95, 99, 99.9), bootstrap=TRUE, npaths=10000)
    Point Forecast  Lo 80 Hi 80  Lo 95 Hi 95 Lo 99 Hi 99 Lo 99.9 Hi 99.9
297         0.9654 -1.390 3.395 -2.626 4.461 -5.85 7.008  -8.353   7.902
298         0.9494 -1.494 3.406 -2.965 4.759 -5.92 7.269  -8.410   8.464

Is This Useful?

hedge.forecast <- fitted.values(fit)

summary(hedge)                     # 296 observations
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 -8.820  -0.252   1.100   0.946   2.060   8.370 
summary(hedge[hedge.forecast > 0]) # 282 observations
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 -8.820  -0.173   1.120   1.020   2.090   8.370 
summary(hedge[hedge.forecast > 1]) # 145 observations
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  -2.65    0.38    1.48    1.39    2.35    8.37 
summary(hedge[hedge.forecast > 2]) # only 8 observations
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   0.42    0.88    1.14    2.54    2.59    8.37